home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Networking / SNMP / SNMP Development / MacSNMP Developer 1.0.2 / Library Manager Interfaces / LibraryManager.h next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  14.4 KB  |  535 lines  |  [TEXT/MPS ]

  1. /*    File:        LibraryManager.h
  2.  
  3.     Contains:    Minimal declarations you need to use the Shared Library Manager.
  4.  
  5.     Copyright:    © 1991-1992 by Apple Computer, Inc., all rights reserved.
  6.  
  7.  
  8. */
  9.  
  10. #ifndef __LIBRARYMANAGER__
  11. #define __LIBRARYMANAGER__
  12.  
  13. #ifndef __STDDEF__
  14. #include <StdDef.h>
  15. #endif
  16.  
  17. #ifndef __TYPES__
  18. #include <Types.h>
  19. #endif
  20.  
  21. #ifndef __STRING__
  22. #include <String.h>
  23. #endif
  24.  
  25. /*******************************************************************************
  26. ** System-wide Defines
  27. ********************************************************************************/
  28.  
  29. #ifndef qDebug
  30. #define qDebug    1
  31. #endif
  32.  
  33. #define UNIX        0
  34. #define MACOS        1
  35. #define KERNELSPACE    0
  36.  
  37. /*******************************************************************************
  38. ** Error Constants
  39. ********************************************************************************/
  40.  
  41. const OSErr    kNoError                    = 0;
  42. const OSErr    kInProgress                    = 1;
  43.  
  44. const OSErr    kNotFound                    = -3120;    // class wasn't found
  45. const OSErr    kNoParent                    = -3121;    // class doesn't have a shared parent
  46. const OSErr    kParentNotFound                = -3122;    // shared parent of class could not be found
  47. const OSErr    kNotRelated                    = -3123;    // the classes are not related
  48. const OSErr    kInvalidObject                = -3124;    // not a valid object
  49.  
  50. const OSErr    kPoolCorrupted                = -3125;
  51. const OSErr    kOutOfMemory                = -3126;
  52.  
  53. const OSErr    kCodeNotLoaded                = -3127;
  54. const OSErr    kCouldNotLoadCode            = -3128;
  55.  
  56. const OSErr    kFilePreflighted            = -3129;    // can't close library file because it is preflighted
  57. const OSErr    kFileNotPreflighted            = -3130;    // failed because library file is not preflighted
  58. const OSErr    kFileNotFound                = -3131;
  59.  
  60. const OSErr kLibraryManagerNotLoaded    = -3132;
  61.  
  62. const OSErr    kDuplicateFound                = -3134;    // duplicate found is collection
  63. const OSErr    kSeedChanged                = -3135;
  64.  
  65. const OSErr    kInternalError                = -3135;
  66. const OSErr    kUnconstructedObject        = -3136;
  67.  
  68. const OSErr    kNotSupported                = -3167;    // matches the XTI error code
  69.  
  70. /**********************************************************************
  71. ** Forward class declarations
  72. ***********************************************************************/
  73.  
  74. #ifdef __cplusplus
  75.  
  76. class    TDynamic;
  77. class    TLibraryManager;
  78. class    TClassID;
  79.  
  80. class    TLibraryFile;
  81. class    TFormattedStream;
  82. class    TMemoryPool;
  83. class    TStandardPool;
  84. class    TLibraryFile;
  85. class    TConfiguration;
  86. class     TClassInfo;
  87. class    TException;
  88. class    TSimpleList;
  89. #else
  90.  
  91. typedef void TDynamic;
  92. typedef void TLibraryManager;
  93. typedef char* TClassID;
  94.  
  95. typedef void TStandardPool;
  96.  
  97. #endif __cplusplus
  98.  
  99. /*******************************************************************************
  100. ** Enums for Memory types
  101. ********************************************************************************/
  102.  
  103. enum ZoneType
  104. {
  105.     kSystemZone = 1, kKernelZone, kApplicZone,
  106.     kCurrentZone, kTempZone
  107. };
  108.  
  109. enum MemoryType
  110. {
  111.     kNormalMemory = 1, kHoldMemory, kLockMemory, kLockMemoryContiguous
  112. };
  113.  
  114. /**********************************************************************
  115. ** Some inlines. Prototypes are also given in Global Routines section
  116. ** to make them easier to read.
  117. ***********************************************************************/
  118.  
  119. #ifdef __cplusplus
  120. extern "C" {
  121. #endif
  122.  
  123. extern TLibraryManager* __gLibraryManager;
  124.  
  125. #ifdef __cplusplus
  126. inline TLibraryManager* GetLocalLibraryManager()
  127. {
  128.     return __gLibraryManager;    // developers, never access __gLibraryManager directly!
  129. };
  130. #else
  131. #define GetLocalLibraryManager() (__gLibraryManager)
  132. #endif
  133.  
  134. /*******************************************************************************
  135. ** Some "C" Global routines
  136. **
  137. ** InitLibraryManager initializes a client to use the LibraryManager. All clients
  138. ** must make this call except for LibraryManager libraries. CleanupLibraryManager
  139. ** should be called when the client is done using the LibraryManager.
  140. **
  141. ** GetLocalLibraryManager can be called after InitLibraryManager is called. If it
  142. ** returns NULL then InitLibraryManager failed.
  143. ********************************************************************************/
  144.  
  145. #ifdef __cplusplus
  146. OSErr                InitLibraryManager(size_t poolsize = 0, ZoneType = kCurrentZone,
  147.                                   MemoryType = kNormalMemory);
  148. #else
  149. OSErr                InitLibraryManager(size_t poolsize, short zoneType, short memType);
  150. #endif
  151.  
  152. void                CleanupLibraryManager();
  153. TLibraryManager*    GetLocalLibraryManager();
  154. TDynamic*            NewObject(const TClassID classID, OSErr*, TStandardPool*);
  155.  
  156. #ifdef __cplusplus
  157. extern void* SLMNewOperator(size_t, TMemoryPool*);    // no need to call this directly
  158. extern void SLMDeleteOperator(void*);                // no need to call this directly
  159. #endif
  160.  
  161. #ifdef __cplusplus
  162. }
  163. #endif
  164.  
  165. /*******************************************************************************
  166. ** CLASS TSimpleDynamic
  167. **
  168. ** A base class for shared-library classes that has no virtual functions.  This
  169. ** class is NOT shared, since it is intended to be a trivial class that just
  170. ** forces the VTable to be at the front of the object.
  171. ********************************************************************************/
  172.  
  173. #ifdef __cplusplus
  174.  
  175. class TSimpleDynamic : public SingleObject 
  176. {
  177.     public:
  178.         virtual                  ~TSimpleDynamic();
  179.         
  180.                 void*            operator new(size_t size, TMemoryPool*);    // from specified pool
  181.                 void*            operator new(size_t);                        // from default pool
  182.                 void            operator delete(void* obj, size_t)
  183.                                     { SLMDeleteOperator(obj); }
  184.  
  185.                 const TClassID&    GetObjectsClassID() const;
  186.                 const TClassID&    GetObjectsParentClassID() const;
  187.                 size_t            GetObjectsSize() const;
  188.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  189.                 TStandardPool*    GetObjectsLocalPool() const;
  190.                 void            SetObjectsLocalPool(TStandardPool*) const;
  191.         
  192.                 Boolean            IsDerivedFrom(const TClassID&) const;
  193.                 
  194.     protected:
  195.                                   TSimpleDynamic();
  196.  
  197.     private:
  198.                                 TSimpleDynamic(const TSimpleDynamic&);
  199.                 void            operator=(const TSimpleDynamic&);
  200. };
  201.  
  202. /*    -----------------------------------------------------------------
  203.     Inline methods for TSimpleDynamic
  204.     ----------------------------------------------------------------- */
  205.  
  206.     inline void* TSimpleDynamic::operator new(size_t size, TMemoryPool* thePool)
  207.     {
  208.         return SLMNewOperator(size, thePool);
  209.     }
  210.     
  211.     inline void* TSimpleDynamic::operator new(size_t size)
  212.     {
  213.         return SLMNewOperator(size, NULL);
  214.     }
  215.  
  216. /*******************************************************************************
  217. ** CLASS TDynamic
  218. **
  219. ** The base class for all shared-library classes.
  220. ********************************************************************************/
  221.  
  222. #define kTDynamicID "!$dyna"
  223.  
  224. enum TraceControlType
  225. {
  226.     kTraceStatus = 1, kTraceOn, kTraceOff
  227. };
  228.  
  229. class TDynamic : public SingleObject 
  230. {
  231.     public:
  232.         virtual                  ~TDynamic();
  233.         
  234.                 void*            operator new(size_t size, TMemoryPool*);    // from specified pool
  235.                 void*            operator new(size_t);                        // from default pool
  236.                 void            operator delete(void* obj, size_t)
  237.                                     { SLMDeleteOperator(obj); }
  238.                                     
  239.  
  240.         const TClassID&            GetObjectsClassID() const;
  241.         const TClassID&            GetObjectsParentClassID() const;
  242.                 size_t            GetObjectsSize() const;
  243.                 TLibraryFile*    GetObjectsLocalLibraryFile() const;
  244.                 TStandardPool*    GetObjectsLocalPool() const;
  245.                 void            SetObjectsLocalPool(TStandardPool*) const;
  246.  
  247.         virtual Boolean            IsValid() const;
  248.         
  249.         virtual    OSErr            Inflate(TFormattedStream&);
  250.         virtual OSErr            Flatten(TFormattedStream&) const;
  251.         virtual TDynamic*        Clone(TStandardPool*) const;
  252.         
  253.         virtual    char*            GetVerboseName(char*) const;
  254.         virtual    void            Dump() const;
  255.         
  256.                 void            Trace(char *formatStr, ...) const;
  257.         virtual    Boolean            TraceControl(TraceControlType) const;
  258.                 Boolean            IsTraceOn() const;    
  259.                 Boolean            TraceOn() const;
  260.                 Boolean            TraceOff() const;
  261.     
  262.                 Boolean            IsDerivedFrom(const TClassID&) const;
  263.                 
  264.     protected:
  265.                                   TDynamic();
  266.  
  267.     private:
  268.                                 TDynamic(const TDynamic&);
  269.                 void            operator=(const TDynamic&);
  270. };
  271.  
  272. /*    -----------------------------------------------------------------
  273.     Inline methods for TDynamic
  274.     ----------------------------------------------------------------- */
  275.  
  276.     inline void* TDynamic::operator new(size_t size, TMemoryPool* thePool)
  277.     {
  278.         return SLMNewOperator(size, thePool);
  279.     }
  280.     
  281.     inline void* TDynamic::operator new(size_t size)
  282.     {
  283.         return SLMNewOperator(size, NULL);
  284.     }
  285.  
  286.     inline Boolean TDynamic::IsTraceOn() const
  287.     {
  288.         return TraceControl(kTraceStatus);
  289.     }
  290.  
  291.     inline Boolean TDynamic::TraceOn() const
  292.     {
  293.         return TraceControl(kTraceOn);
  294.     }
  295.  
  296.     inline Boolean TDynamic::TraceOff() const
  297.     {
  298.         return TraceControl(kTraceOff);
  299.     }
  300.  
  301. #endif __cplusplus
  302.     
  303. /*******************************************************************************
  304. ** Class TClassID
  305. ********************************************************************************/
  306.  
  307. #ifdef __cplusplus
  308.  
  309. const size_t    kMaxClassIDSize = 64;
  310.  
  311. class TClassID : public SingleObject 
  312. {
  313.     public:
  314.         void*        operator new(size_t, size_t strLen)
  315.                     {
  316.                         return SLMNewOperator(
  317.                             (sizeof(TClassID) - 
  318.                              sizeof(char[kMaxClassIDSize]) + 
  319.                              strLen), NULL);
  320.                     }
  321.                         
  322.         void        operator delete(void* obj, size_t)
  323.                         { SLMDeleteOperator(obj); }
  324.  
  325.                     TClassID();
  326.                     TClassID(const char*);
  327.                     TClassID(const TClassID&);
  328.  
  329.         TClassID&    operator=(const char*);
  330.         Boolean        operator==(const TClassID&) const;    // compare with another TClassID
  331.         Boolean        operator==(const char*) const;        // compare with type string
  332.         short        Compare(const char*) const;
  333.  
  334.     private:
  335.         char                fClassIDStr[kMaxClassIDSize];
  336. };
  337.  
  338. /*    -----------------------------------------------------------------
  339.     Inline methods for TClassID
  340.     ----------------------------------------------------------------- */
  341.  
  342.     inline TClassID::TClassID()
  343.     {
  344.         fClassIDStr[0] = 0;
  345.     }
  346.     
  347.     inline TClassID::TClassID(const char* theTypeStr)
  348.     {
  349.         strcpy(fClassIDStr, theTypeStr);
  350.     }
  351.     
  352.     inline TClassID::TClassID(const TClassID& classID)
  353.     {
  354.         strcpy(fClassIDStr, (const char*)&classID);
  355.     }
  356.     
  357.     inline short TClassID::Compare(const char* classIDStr) const
  358.     {
  359.         return (strcmp(classIDStr, fClassIDStr));
  360.     }
  361.     
  362.     inline Boolean TClassID::operator==(const char* classID) const
  363.     {
  364.         return (Compare(classID) == 0);
  365.     }
  366.  
  367.     inline Boolean TClassID::operator==(const TClassID& classID) const
  368.     {
  369.         return (Compare((const char*)&classID) == 0);
  370.     }
  371.     
  372.     inline TClassID& TClassID::operator=(const char* theTypeStr)
  373.     {
  374.         strcpy(fClassIDStr, theTypeStr);
  375.         return *this;
  376.     }
  377.  
  378.     inline const TClassID& ClassID(const char* str)
  379.     {
  380.         return *(const TClassID*)str;
  381.     }
  382.     
  383. #endif __cplusplus
  384.  
  385. /*******************************************************************************
  386. ** Class TLibraryManager
  387. **
  388. ** The user's interface to the world! 
  389. ********************************************************************************/
  390.  
  391. #ifdef __cplusplus
  392.  
  393. #define kTLibraryManagerID "!$lmgr"
  394.  
  395. class TLibraryManager : public TDynamic 
  396. {
  397.     private:
  398.         virtual                    ~TLibraryManager();
  399.                                 TLibraryManager(TStandardPool* = NULL, TLibraryFile* = NULL);
  400.  
  401.     public:
  402.         virtual    void            Dump() const;
  403.  
  404.         // New Methods
  405.         
  406.         virtual    TDynamic*        NewObject(const TClassID& classID,
  407.                                     OSErr* = NULL, TStandardPool* = NULL) const;
  408.         virtual    TDynamic*        NewObject(const TClassID& classID, const TClassID& baseClassID,
  409.                                     OSErr* = NULL, TStandardPool* = NULL) const;
  410.         virtual    TDynamic*        NewObject(const TFormattedStream&,
  411.                                     OSErr* = NULL, TStandardPool* = NULL) const;
  412.  
  413.         virtual TClassInfo*     GetClassInfo(const TClassID& classID, OSErr* err=NULL) const;
  414.         virtual OSErr             GetParentClassID(const TClassID& classID, TClassID& parentClassID) const;
  415.  
  416.         virtual OSErr            VerifyClass(const TClassID& classID, const TClassID& baseClassID) const;
  417.         virtual OSErr            VerifyClass(const TDynamic* theObject, const TClassID& baseClassID) const;
  418.  
  419.         virtual Boolean            LoadClass(const TClassID& classID, Boolean loadAll = false, OSErr* = NULL) const;
  420.         virtual void            UnloadClass(const TClassID& classID) const;
  421.         virtual Boolean            IsClassLoaded(const TClassID& classID) const;
  422.  
  423.                 void            SetObjectPool(TStandardPool*);
  424.                 TStandardPool*    GetObjectPool() const;
  425.                 void            SetDefaultPool(TStandardPool*);
  426.                 TStandardPool*    GetDefaultPool() const;
  427.                 Ptr                GetGlobalWorld() const;
  428.  
  429.                 TLibraryFile*    GetLibraryFile() const;
  430.         
  431.         virtual Boolean            TraceLogOn();
  432.         virtual Boolean            TraceLogOff();
  433.         
  434.         virtual    void            RegisterDynamicObject(TDynamic*);
  435.         virtual    void            UnRegisterDynamicObject(TDynamic*);
  436.         
  437.  
  438.     private:
  439.                                 TLibraryManager(const TLibraryManager&);
  440.                 void            operator=(const TLibraryManager&);
  441.  
  442.     private:        
  443.         TStandardPool*            fPool;            // pool used for new objects and local pool
  444.         TLibraryFile*            fLibraryFile;
  445.         TStandardPool*            fDefaultPool;
  446.         Ptr                        fGlobalWorld;
  447.  
  448. };
  449.  
  450. /*    -----------------------------------------------------------------
  451.     Inline Methods for TLibraryManager
  452.     ----------------------------------------------------------------- */
  453.     
  454.     inline TStandardPool* TLibraryManager::GetObjectPool() const
  455.     {
  456.         return fPool;
  457.     }
  458.     
  459.     inline void TLibraryManager::SetObjectPool(TStandardPool* thePool)
  460.     {
  461.         fPool = thePool;
  462.     }
  463.         
  464.     inline TStandardPool* TLibraryManager::GetDefaultPool() const
  465.     {
  466.         return fDefaultPool;
  467.     }
  468.  
  469.     inline void TLibraryManager::SetDefaultPool(TStandardPool* thePool)
  470.     {
  471.         fDefaultPool = thePool;
  472.     }
  473.     
  474.     inline Ptr TLibraryManager::GetGlobalWorld() const
  475.     {
  476.         return fGlobalWorld;
  477.     }
  478.     
  479.     inline TLibraryFile* TLibraryManager::GetLibraryFile() const
  480.     {
  481.         return fLibraryFile;
  482.     }
  483.  
  484. /*    -------------------------------------------------------------------------
  485.     Inline methods for TDynamic
  486.     ------------------------------------------------------------------------- */
  487.  
  488.     inline Boolean TDynamic::IsDerivedFrom(const TClassID& id) const
  489.     {
  490.         return (GetLocalLibraryManager()->VerifyClass(this, id) == kNoError);
  491.     }
  492.  
  493. /*    -------------------------------------------------------------------------
  494.     Inline methods for TSimpleDynamic
  495.     ------------------------------------------------------------------------- */
  496.  
  497.     inline const TClassID& TSimpleDynamic::GetObjectsClassID() const
  498.     {
  499.         return ((const TDynamic*)this)->GetObjectsClassID();
  500.     }
  501.  
  502.     inline const TClassID& TSimpleDynamic::GetObjectsParentClassID() const
  503.     {
  504.         return ((const TDynamic*)this)->GetObjectsParentClassID();
  505.     }
  506.  
  507.     inline size_t TSimpleDynamic::GetObjectsSize() const
  508.     {
  509.         return ((const TDynamic*)this)->GetObjectsSize();
  510.     }
  511.  
  512.     inline TLibraryFile* TSimpleDynamic::GetObjectsLocalLibraryFile() const
  513.     {
  514.         return ((const TDynamic*)this)->GetObjectsLocalLibraryFile();
  515.     }
  516.  
  517.     inline TStandardPool* TSimpleDynamic::GetObjectsLocalPool() const
  518.     {
  519.         return ((const TDynamic*)this)->GetObjectsLocalPool();
  520.     }
  521.  
  522.     inline void TSimpleDynamic::SetObjectsLocalPool(TStandardPool* pool) const
  523.     {
  524.         ((const TDynamic*)this)->SetObjectsLocalPool(pool);
  525.     }
  526.  
  527.     inline Boolean TSimpleDynamic::IsDerivedFrom(const TClassID& id) const
  528.     {
  529.         return ((const TDynamic*)this)->IsDerivedFrom(id);
  530.     }
  531.     
  532. #endif __cplusplus
  533.  
  534. #endif
  535.